package tests.mapeditor;

import java.awt.Dimension;

import tests.mapeditor.moks.MockMapCanvas;
import tests.mapeditor.moks.MockMapEditorView;
import tests.mapeditor.moks.MockTileBrowserPanel;
import tests.mapeditor.moks.MockTilePaletePanel;
import harima.agameditor.mapeditor.control.MapEditorController;
import harima.agameditor.mapeditor.control.MapEditorServices;
import harima.agameditor.mapeditor.control.MapEditorState;
import harima.agameditor.mapeditor.ui.MapEditorView_panel;
import harima.agamengine.mapmodel.MapModel;

import junit.framework.TestCase;

public class MapEditorControllerFixture extends TestCase {

	MapEditorController controller;
	MockMapEditorView view;
	
	
	@Override
	protected void setUp() throws Exception {
		controller = new MapEditorController();
		view = new MockMapEditorView();
		controller.setView(view);
	}
	
	public void test_CreatesEditorObjects_ControlerIsCreated_Always() throws Exception {
		controller = new MapEditorController();
		MapEditorState state = controller.getEditorState();
		MapEditorServices services = controller.getServices();
		assertNotNull(state);
		assertNotNull(services);
	}
	
	public void test_SetsWorkingMapInEditorState_SetWorkingMapRequested_Always() throws Exception {
		MapModel map = new MapModel(new Dimension(), ""); 
		controller.setWorkingmap(map);
		MapEditorState state = controller.getEditorState();
		assertNotNull(state.getMap());
		assertSame(map, state.getMap());
	}
	
	public void test_RefreshesTileListAndTilePalete_SetWorkingMapRequested_Always() throws Exception {
		MockTileBrowserPanel panel = new MockTileBrowserPanel();
		view.addPanel(panel);
		controller.setWorkingmap(new MapModel( new Dimension(), ""));
		assertEquals(1, panel.CCRefresgTileList);
	}
	
	public void test_ReloadsTilePalete_SetWorkingMapRequested_Always() throws Exception {
		MockTilePaletePanel panel = new MockTilePaletePanel();
		view.addPanel(panel);
		controller.setWorkingmap(new MapModel( new Dimension(), ""));
		assertEquals(1, panel.CCReloadPalete);
	}
	
	public void test_CausesRepainOnMaoCanvas_SetWorkingMapRequested_Always() throws Exception {
		MockMapCanvas canvas = new MockMapCanvas();
		view.addPanel(canvas);
		controller.setWorkingmap(new MapModel(new Dimension(), ""));
		assertEquals(5, canvas.CCRepaint);
	}
	
	public void test_EnablesMapSave_SetWirkongMapRequested_Always() throws Exception {
		controller.setWorkingmap(new MapModel(new Dimension(), ""));
		assertEquals(1, view.CCEnableMapSave);
		assertTrue(view.LastEnableMapSave);
		
	}
	

}
